<!--
 * @Description: 添加日报弹框
 * @Author: Huang Junjie
 * @Date: 2021-06-15 12:27:15
 * @LastEditTime: 2021-06-25 18:10:05
 * @LastEditors: Huang Junjie
-->
<template>
  <div>
    <base-dialog
      class="dialog_box"
      width="40%"
      :visible.sync="dialog.visible"
      :title="dialog.title"
      :loading="dialog.loading"
      :disabled="dialog.disabled"
      @updateData="updateData"
      @open="beforeOpenDialog">
      <el-form
        ref="dataForm"
        :model="dialog.form"
        :rules="dialog.rules"
        :disabled="dialog.disabled"
        label-width="100px">
        <el-form-item label="部门" prop="uploadDeptId">
          <select-tree
            v-model="dialog.form.uploadDeptId"
            size="medium"
            :options="dialog.dataList.deptTreeArr"
            :props="{ label: 'label', value: 'id', parent: 'parentId', children: 'children' }"
            :disabled="dialog.type === 'view' ? true : false" />
        </el-form-item>
        <el-form-item label="日期" prop="uploadDate">
          <el-date-picker
            v-model="dialog.form.uploadDate"
            :picker-options="pickerOptions"
            placeholder="请选择日期"
            type="date"
            value-format="yyyy-MM-dd" />
        </el-form-item>
      </el-form>
    </base-dialog>
  </div>
</template>

<script>
export default {
  props: {
    // 弹框参数
    dialog: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      // 时间选择器配置
      pickerOptions: {
        disabledDate: time => {
          return time.getTime() > Date.now() - 8.64e6
        }
      }
    }
  },
  methods: {
    // 初始化
    beforeOpenDialog() {
      this.$nextTick(() => {
        this.$refs.dataForm.clearValidate()
      })
    },

    // 回调方法
    updateData() {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          this.dialog.loading = true
          this.$emit('updateData', this.dialog.form)
        }
      })
    }
  }
}
</script>
